import os
import sys
import shutil
import random

def main(argv):
    directory = argv[0] # './data/SM/train4/0/'  一定要以斜杠结尾

    # 只枚举文件
    # for category in range(0,9):
    fileList = []  
        
    for filename in os.listdir(directory):
        file_path = os.path.join(directory, filename)
        if os.path.isfile(file_path):
            fileList.append(filename)

    maxIdx = [0,0,0,0,0,
            0,0,0,0,0]
        
    for fn in fileList:
        items = str.split(fn, '.')
        if int(items[1]) > maxIdx[int(items[0])]:
            maxIdx[int(items[0])] = int(items[1])

    print(maxIdx)

    category = 0
    for c in range(0, 10):
        if maxIdx[c] > 0 and maxIdx[c] < 16:
            for nidx in range(maxIdx[c] + 1, 17):
                srcFn = str(c) + "." + str(random.randint(1, maxIdx[c])) + ".png"
                dstFn = str(c) + "." + str(nidx) + ".png"
                print("cp " + srcFn + " " + dstFn)
                shutil.copy(directory + srcFn, directory + dstFn)

if __name__ == "__main__":
    main(sys.argv[1:])